//
//  BaseWorld.h
//  IsoCplus
//
//  Created by zhouzhanglin on 15/9/17.
//
//

#ifndef __IsoCplus__BaseWorld__
#define __IsoCplus__BaseWorld__

#include "IsoWorld.h"
#include "iso/Matrix.h"
#include "cocos2d.h"

const int GRID_SIZE = 40; //size大小
const int GRID_X = 15 ; //x轴的网格大小
const int GRID_Z = 15;  // z轴的网格大小
const int MAP_WIDTH = 1024*2;
const int MAP_HEIGHT = 768*2;


struct MyTouch
{
    cocos2d::Vec2 began;
    cocos2d::Vec2 current;
    cocos2d::Vec2 prev;
    std::string type;
    int tid;
    
    MyTouch(cocos2d::Vec2 &began,cocos2d::Vec2 &current,cocos2d::Vec2 &prev,const std::string& type,int tid )
    {
        this->began = began;
        this->current = current;
        this->prev = prev;
        this->type = type;
        this->tid = tid;
    }
};

class BaseWorld:public IsoWorld
{
    
protected:
    
    float _moveSpeed = 0;
    bool _isClickNode = false;
    Matrix _scaleMatrix;
    PathGrid *_gridData;
    float _endX =0 ;
    float _endY = 0;
    float _beganWorldX=0;
    float _beganWorldY = 0;
    std::vector<MyTouch> _touches;
    
protected:
    /**
     *  每帧执行
     *
     *  @param dt
     */
    virtual void update(float dt) override;
    virtual void onTouchesBegan(const std::vector<cocos2d::Touch*>&, cocos2d::Event*);
    virtual void onTouchesMoved(const std::vector<cocos2d::Touch*>&, cocos2d::Event*);
    virtual void onTouchesEnded(const std::vector<cocos2d::Touch*>&, cocos2d::Event*);
    
    /**
     *  执行了点击，在子类中重写
     *
     *  @param gridPos 点击的网格坐标
     */
    virtual void onClick(const cocos2d::Vec2 &gridPos) = 0;
    
public:
    
    virtual bool init () override;
    virtual bool init(unsigned int size,unsigned int spanX,unsigned int spanZ) override;
    
    virtual void onEnter() override;
    
    /**
     *  限制地图移动范围
     */
    void modifyEndPosition();
    
    /**
     *  在某个点缩放iso地图
     *
     *  @param sc      缩放变化值
     *  @param middleX 缩放点
     *  @param middleY 缩放点
     */
    void scaleWorld(float sc , float middleX,float middleY);
};



#endif /* defined(__IsoCplus__BaseWorld__) */
